//
//  SNCompilePlanOtherCell.m
//  ZhuoxinAgriculture
//
//  Created by stone on 16/12/26.
//  Copyright © 2016年 stone. All rights reserved.
//

#import "SNPesticideInformationController.h"
#import "SNFertilizerInformationController.h"
#import "UIImageView+TapGesture.h"
#import "SNCompilePlanFertilizerCell.h"
#import "SNPlanListLabel.h"
#import "SNCompilePlanOtherButton.h"
#import "SNPlanListViewController.h"
@interface SNCompilePlanFertilizerCell()
@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet UILabel *leftLabel;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iconImageViewHeightLayoutConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iconImageViewWidthLayoutConstraint;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *leftLabels;

@property (weak, nonatomic) IBOutlet UILabel *fertTypes;
@property (weak, nonatomic) IBOutlet UILabel *fertTotal;
@property (weak, nonatomic) IBOutlet UILabel *fertContent;
@property (weak, nonatomic) IBOutlet UILabel *fertBrand;
@property (weak, nonatomic) IBOutlet UILabel *fertManu;
@property (weak, nonatomic) IBOutlet UILabel *fertPrice;
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UIButton *editButton;
@property (weak, nonatomic) IBOutlet UIButton *deleteButton;

@end
@implementation SNCompilePlanFertilizerCell

- (NSString *)getFertContentNameWithFertTypes:(NSString *)fertTypes fertContent:(NSString *)fertContent
{
    if(fertTypes.integerValue == 1){
        switch (fertContent.integerValue) {
            case 1:
                return @"氮肥-46%氮";
                
            case 2:
                return @"二胺-18%氮，46%磷";
                
            case 3:
                return @"氯化钾-60%钾";
                
            case 4:
                return @"硫酸钾-50%钾";
                
            default:
                return @"";
                
        }
    }else if(fertTypes.integerValue == 2){
        switch (fertContent.integerValue) {
            case 1:
                return @"15%氮，15%磷，15%钾";
                
            case 2:
                return @"17%氮，17%磷，17%钾";
                
            case 3:
                return @"18%氮，18%磷，18%钾";
                
            case 4:
                return @"其他";
                
            default:
                return @"";
                
        }
    }else if(fertTypes.integerValue == 3){
        switch (fertContent.integerValue) {
            case 1:
                return @"15%氮，15%磷，15%钾";
                
            case 2:
                return @"17%氮，17%磷，17%钾";
                
            case 3:
                return @"18%氮，18%磷，18%钾";
                
            case 4:
                return @"其他";
                
            default:
                return @"";
                
        }
    }else{
        return @"";
    }
}
/** 点击编辑按钮 */
- (IBAction)editButtonClicked:(UIButton *)sender {
    NSLog(@"%@ | %s",self.class,__func__);
    SNFertilizerInformationController * vc = [SNFertilizerInformationController new];
    SNProductionPlanListFertlist * productionPlanListFertlist = self.productionPlanListResult.fertList[self.indexPath.row];
    vc.productionPlanListFertlist = productionPlanListFertlist;
    [self.nav pushViewController:vc animated:YES];
}
/** 点击删除按钮 */
- (IBAction)deleteButtonClicked:(UIButton *)sender {
    NSLog(@"%@ | %s",self.class,__func__);
    if ([self.delegate respondsToSelector:@selector(deleteInfomationWithIndexPath:object:)]) {
        [self.delegate deleteInfomationWithIndexPath:self.indexPath object:self];
    }
}
-(void)setProductionPlanListResult:(SNProductionPlanListResult *)productionPlanListResult{
    _productionPlanListResult = productionPlanListResult;
    
    SNProductionPlanListFertlist * productionPlanListFertlist = productionPlanListResult.fertList[self.indexPath.row];
    self.fertTypes.text = [NSString stringWithFormat:@"* 肥料种类 : %@",productionPlanListFertlist.fertTypesName];
    self.fertTotal.text = [NSString stringWithFormat:@"* 肥料总量 : %@吨",productionPlanListFertlist.fertTotal];
    self.fertContent.text = [NSString stringWithFormat:@"   含量 : %@",[self getFertContentNameWithFertTypes:productionPlanListFertlist.fertTypes fertContent:productionPlanListFertlist.fertContent]];
    self.fertBrand.text = [NSString stringWithFormat:@"   品牌 : %@",productionPlanListFertlist.fertBrand];
    self.fertManu.text = [NSString stringWithFormat:@"   厂家 : %@",productionPlanListFertlist.fertManu];
    self.fertPrice.text = [NSString stringWithFormat:@"* 价格 : %@元/吨",productionPlanListFertlist.fertPrice];
    
    [self.leftLabels enumerateObjectsUsingBlock:^(UILabel *  obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [SNUtils specialLabelWithstring:obj.text keyString:@"*" label:obj color:HexRGB(0xFF5D04)];
    }];
}
- (void)setModel:(Fert *)model{
    _model = model;
    self.fertTypes.text = [NSString stringWithFormat:@"肥料种类 : %@",model.fertTypes];
    self.fertTotal.text = [NSString stringWithFormat:@"肥料总量 : %@吨",model.fertTotal];
    self.fertContent.text = [NSString stringWithFormat:@"含量 : %@",model.fertContent];
    self.fertBrand.text = [NSString stringWithFormat:@"品牌 : %@",model.fertBrand];
    self.fertManu.text = [NSString stringWithFormat:@"厂家 : %@",model.fertManu];
    self.fertPrice.text = [NSString stringWithFormat:@"价格 : %@元/毫升",model.fertPrice];
    
    [self awakeFromNib];
}

- (void)configCellWithTitle:(NSString *)title imageName:(NSString *)imageName indexPath:(NSIndexPath *)indexPath saveButtonCurrentTitle:(NSString *)saveButtonCurrentTitle{
    _indexPath = indexPath;
    self.iconImageView.image = [UIImage imageNamed:imageName];
    
    self.leftLabel.text = [NSString stringWithFormat:@"* %@",title];
    self.leftLabel.textColor = HexRGB(0x04177A);
    [SNUtils specialLabelWithstring:self.leftLabel.text keyString:@"*" label:self.leftLabel color:HexRGB(0xFF5D04)];
    
    
    UIImage * image = self.iconImageView.image;
    self.iconImageViewWidthLayoutConstraint.constant = 15;
    self.iconImageViewHeightLayoutConstraint.constant = self.iconImageViewWidthLayoutConstraint.constant * image.size.height / image.size.width;
    
    if (indexPath.row == 0) {
        self.topView.hidden = YES;
    }else{
        self.topView.hidden = NO;
    }
    
    if ([saveButtonCurrentTitle isEqualToString:@"提交审批"]) {
        self.editButton.hidden = YES;
        self.deleteButton.hidden = YES;
    }else{
        self.editButton.hidden = NO;
        self.deleteButton.hidden = NO;
    }
    
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        CALayer * layer = [CALayer layer];
        
        layer.frame = CGRectMake(50, 0, [UIScreen mainScreen].bounds.size.width - 50 - 15 - 12, 1);
        /** color */
        layer.backgroundColor = HexRGB(0xE2E2E2).CGColor;
        
        [self.contentView.layer addSublayer:layer];
    }
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [SNUtils specialLabelWithstring:self.leftLabel.text keyString:@"*" label:self.leftLabel color:HexRGB(0xFF5D04)];
    
    UIImage * image = self.iconImageView.image;
    
    self.iconImageViewHeightLayoutConstraint.constant = 15 * image.size.height / image.size.width;
    
    [self.leftLabels enumerateObjectsUsingBlock:^(UILabel  * obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        [SNUtils specialLabelWithstring:obj.text keyString:@"*" label:obj color:HexRGB(0xFF5D04)];
    }];
}

@end
